/*
 * Copyright (C) 2018 Baidu, Inc. All Rights Reserved.
 */
package com.hongye.jpademo;

import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/user", produces = APPLICATION_JSON_VALUE)
public class UserController {

    @Resource
    private UserRepo userRepo;

    @Resource
    private UserServer userServer;

    @RequestMapping("/list")
    public List<User> userList() {
        return (List<User>) userRepo.findAll();
    }

    @RequestMapping(value = "/new", method = POST)
    public Boolean addUser(@RequestBody UserAddForm addForm) {
        return userServer.addUserManualValidate(addForm);
    }

    @RequestMapping(value = "/new/v2", method = POST)
    public String addUserV2(@RequestBody UserAddForm addForm) {
        return String.valueOf(userServer.addUserSystemValidate(addForm));
    }
}
